package com.carleasoft.mps.adu.business.org.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.adu.business.org.bean.po.OrgPageQueryPo;
import com.carleasoft.mps.adu.business.org.bean.po.OrgPo;
import com.carleasoft.mps.adu.business.org.service.OrgService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.SortPo;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Description: 组织 controller</p>
 * @since 2020/4/28
 * @author ztm
 */
@RestController
@RequestMapping("/org")
public class OrgController {

    @Autowired
    private OrgService orgService;

    /**
     * 页面
     * @param orgPageQueryPo
     * @return
     */
    @PostMapping ("/list")
    public R pageQuery(@RequestBody OrgPageQueryPo orgPageQueryPo){
        return R.ok(orgService.pageQuery(new Page(orgPageQueryPo.getCurrent(),orgPageQueryPo.getSize()),orgPageQueryPo));
    }


    /**
     * 添加组织
     * @param orgPo
     * @return 响应信息
     */
    @PostMapping("/add")
    public R add(@RequestBody OrgPo orgPo) {
        IBeanUtil.paramVerify(orgPo, "organizationNumber", "organizationName");
        return R.ok(orgService.add(orgPo));
    }

    /**
     * 根据组织编码删除组织
     * @param orgPo
     * @return
     */
    @PostMapping("/delete")
    public R deleteOrgByCode(@RequestBody OrgPo orgPo) {
        IBeanUtil.paramVerify(orgPo, "organizationCode");
        return R.result(orgService.deleteOrgByCode(orgPo));
    }

    /**
     * 修改组织信息
     * @param orgPo
     * @return
     */
    @PostMapping("/update")
    public R updateOrgInfo(@RequestBody OrgPo orgPo) {
        IBeanUtil.paramVerify(orgPo, "organizationCode");
        return R.ok(orgService.updateOrgByCode(orgPo));
    }

    /**
     * 排序
     * @param sortPo
     * @return
     */
    @PostMapping("/updateSort")
    public R updateSort(@RequestBody SortPo sortPo){
        IBeanUtil.paramVerify(sortPo, "ownCode");
        return R.result(orgService.updateSort(sortPo));
    }

}
